package top.fullj.actor;

import java.util.LinkedList;
import java.util.List;

/**
 * @author wurenhai
 * @since 2018/3/11
 */
public class ActorSelection {

    public void tell(Object message) {
        tell(message, ActorRef.NO_SENDER);
    }

    public void tell(Object message, ActorRef sender) {
        for (ActorRef a : selections) {
            a.tell(message, sender);
        }
    }

    private final List<ActorRef> selections = new LinkedList<>();

    ActorSelection(ActorRef actor) {
        selections.add(actor);
    }

    ActorSelection(List<ActorRef> actors) {
        selections.addAll(actors);
    }

    void merge(ActorSelection selection) {
        selections.addAll(selection.selections);
    }

}
